Deep Dive
[misc]
Deep Dive
Worth digging into these tricks.
- Download: sar2020_flag.txt
Recon
The txt file is a matroshka archive.
Code
Automatically unpack based on file signatures. We need (at least) cargo install zipcat
.
unpack.sh
:
#!/bin/bash
INPUT="$1"
FTYPE=`file ${INPUT}`
if [[ "$FTYPE" == *"POSIX tar"* ]]; then
echo "TAR"
tar -xOvf "$INPUT" > tmp
cp tmp $INPUT
elif [[ "$FTYPE" == *"Zip archive data"* ]]; then
echo "ZIP"
zipcat -s "$INPUT" > tmp
cp tmp $INPUT
elif [[ "$FTYPE" == *"bzip2 compressed"* ]]; then
echo "ZIP"
bzcat "$INPUT" > tmp
cp tmp $INPUT
elif [[ "$FTYPE" == *"gzip compressed data"* ]]; then
echo "ZIP"
zcat "$INPUT" > tmp
cp tmp $INPUT
elif [[ "$FTYPE" == *"XZ compressed data"* ]]; then
echo "ZIP"
xzcat "$INPUT" > tmp
cp tmp $INPUT
else
echo "NOT RECOGNIZED"
echo ${FTYPE}
fi
Let it run for a while:
while true; do ./unpack.sh sar2020_flag.txt; done
Untill you see:
sar2020_flag.txt: ASCII text, with no line terminators
Cat the flag:
cat sar2020_flag.txt
FLAG{matri0sha256}
Flag
FLAG{matri0sha256}